package se137.hrbust.hlgshopping137.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import se137.hrbust.hlgshopping137.service.Cart137Service;
import se137.hrbust.hlgshopping137.utils.Result137;

@RestController
@RequestMapping("/cart")
public class CartController137 {
    @Autowired
    Cart137Service cartservice;
    @RequestMapping("/add")
    public Result137 addCart(Long skuid, int pnum){
        Boolean result = cartservice.addCart(skuid, pnum);
        return result ?  new Result137().ok("添加成功") : new Result137().fail("添加失败");
    }

    @RequestMapping("/list")
    public Result137 ListCart(){
        return cartservice.ListCart();
    }
    @RequestMapping("/del/{id}")
    public Result137 delCart(@PathVariable("id") Long id){
        return cartservice.delCart(id);
    }
    @RequestMapping("/update")
    public Result137 updateCartNum(Long cid,int num){
        return cartservice.updateCartNum(cid, num);
    }
}
